package com.until;


import com.model.MyLog;
import com.service.MylogService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;



@Component
@EnableScheduling

public class AlarmlogTask {

    private static final SimpleDateFormat myFormat=new SimpleDateFormat("YYYY-MM-DD HH:mm:ss");
    private int count=0;

    @Autowired
    private MylogService mylogService;


    @Scheduled(fixedRate = 10000)
    public void runInsert() throws InterruptedException {
        MyLog myLog = new MyLog();

        int temp= (int) System.currentTimeMillis();

//        MyLog.setUserID(temp%100);
//        MyLog.setDotime(myFormat.format(new Date()));
//        MyLog.setDoname("addFromAlarm");
//        MyLog.setIPAddress("192.168.0."+Integer.toString((temp%255)));


        MylogService.addMylog();
        System.out.println(Thread.currentThread().getName()+"===>"+System.currentTimeMillis()/1000);

    }


    @Scheduled(fixedDelay = 5000)
    public void runAll() throws InterruptedException {
        Thread.sleep(5000);
        MyLog myLog = new MyLog();
        System.out.println("统计所有");

        List<MyLog> MyLogList=MylogService.getAllMyLogs(myLog);
        System.out.println("===============");
        System.out.println("共有"+MyLogList.size()+"条记录");

        for (MyLog temp : MyLogList) {
            System.out.println(temp.toString());
            System.out.println();
        }

        System.out.println("================");

        System.out.println(Thread.currentThread().getName()+"====>"+System.currentTimeMillis()/1000);
    }

    @Scheduled(fixedDelay = 5000)
    public  void runLast10 () throws InterruptedException {
        Thread.sleep(5000);
        MyLog myLog = new MyLog();
        System.out.println("查后10条");

        List<MyLog> MyLogList=MylogService.getLast10(myLog);
        System.out.println("================");

        for (MyLog temp: MyLogList) {
            System.out.println(temp.toString());
        }

        System.out.println("==================");
        System.out.println(Thread.currentThread().getName()+"===>"+System.currentTimeMillis()/1000);
    }
}
